Introduction

You previously recapped the key principles of navigation that make it easier for a user to navigate an app or website. This includes how to set up an intuitive and logical structure. In this exercise, you’ll practice applying these principles as you add more screens to the previously created onboarding page and set up navigation between them.

Scenario

Consider for a moment what information a user would want out of an app for ordering food. You might agree that users want a list of the menu items that are available. With this in mind, let’s put together a navigation flow that displays a home screen with the menu information and hook up the registration button from the onboarding page you created previously to navigate to this new screen.

This list of menu items is stored in a remote server and once queried, delivers a JSON file. You decode the JSON file and save its contents to Core Data. Then, you display its items on a list.

The list is contained in the lower half area (marked in red) of the screen:

This area will display a list of the food retrieved and decoded from the remote server and stored in Core Data.

Although you will fetch and display menu data in the following exercises, it is good to understand the overall design in this step when creating the screen that will hold this data. The following flowchart illustrates the navigation requirements:

Instructions

Use the same project as in the previous exercise, as you will continue to develop the same project.

Step 1: Adding a new home screen

Tip : If you are having trouble implementing any of the steps above, review the following resource from the "Create the User Interface in SwiftUI" course:

Step 2: Adding a new Menu screen to hold the menu information

Tip: If you are having trouble implementing any of the previous steps, review the following resources in the “Create the user interface with SwiftUI” course:

Step 3: Add the new Menu screen as a tab item on the Home screen

Open the Home file and follow the steps below to add a tab to the TabView :

Tip : If you are having trouble implementing any of the steps above, review the following resource from the "Create the User Interface in SwiftUI" course:

Step 3: Add a navigation action to show home page from the registration page

Open the Onboarding file (from the previous exercise) and follow the steps below to connect two pages via the navigation:

Tip: If you are having trouble implementing any of the previous steps, review the following resources in the “Create the user interface with SwiftUI” course:

Step 4: Run the project

Run the project and enter some details inside the registration fields and press "Register". It should take you to the home screen which should show a single tab at the bottom that should be selected by default. You should see the menu screen with the text elements you added in the previous steps. You can also try to press the registration button without entering any details inside the text fields and it should perform no action.

To style your views in a more advanced way, you can refer to other lesson items in the Create the user interface with SwiftUI course , as well as the following documentation:

Conclusion

By completing this exercise, you’ve created a new home screen that will later display items from Little Lemon's menu. You also set up an intuitive navigation flow that will show the newly created home screen when the user presses the Register button on the Onboarding screen.